#include "GacGen.h"

/***********************************************************************
Codegen::Utility
***********************************************************************/

void WriteFileComment(const WString& name, bool doNotModify, StreamWriter& writer)
{
	writer.WriteLine(L"/***********************************************************************");
	writer.WriteLine(L"Vczh Library++ 3.0");
	writer.WriteLine(L"Developer: Zihan Chen(vczh)");
	writer.WriteLine(L"GacUI::" + name);
	writer.WriteLine(L"");
	writer.WriteLine(L"This file is generated by: Vczh GacUI Resource Code Generator");
	if (doNotModify)
	{
		writer.WriteLine(L"************************************************************************");
		writer.WriteLine(L"DO NOT MODIFY");
	}
	writer.WriteLine(L"***********************************************************************/");
	writer.WriteLine(L"");
}

void FillReflectionNamespaces(List<WString>& namespaces)
{
	namespaces.Add(L"vl");
	namespaces.Add(L"reflection");
	namespaces.Add(L"description");
}

WString WriteNamespace(List<WString>& currentNamespaces, List<WString>& namespaces, StreamWriter& writer)
{
	vint common = 0;
	for (vint i = 0; i < currentNamespaces.Count() && i < namespaces.Count(); i++)
	{
		if (currentNamespaces[i] == namespaces[i])
		{
			common++;
		}
		else
		{
			break;
		}
	}

	for (vint i = 0; i < currentNamespaces.Count() - common; i++)
	{
		WString prefix;
		for (vint j = 0; j < currentNamespaces.Count() - i - 1; j++)
		{
			prefix += L"\t";
		}
		writer.WriteLine(prefix + L"}");
	}

	WString prefix;
	FOREACH_INDEXER(WString, ns, i, namespaces)
	{
		if (i >= common)
		{
			writer.WriteLine(prefix + L"namespace " + ns);
			writer.WriteLine(prefix + L"{");
		}
		prefix += L"\t";
	}

	CopyFrom(currentNamespaces, namespaces);
	return prefix;
}

void WriteNamespaceStop(List<WString>& currentNamespaces, StreamWriter& writer)
{
	List<WString> namespaces;
	WriteNamespace(currentNamespaces, namespaces, writer);
}